package com.zklh.leetcode.interviewTop150;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 用最少数量的箭引爆气球算法实现
 */
public class Solution452 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparing(point -> point[0]));
        int[] union = new int[2];
        union[0] = points[0][0];
        union[1] = points[0][1];
        int shotCount = 1;
        for (int[] point : points) {
            if (point[0] > union[1]) {
                union[0] = point[0];
                union[1] = point[1];
                shotCount++;
            } else {
                union[0] = point[0];
                union[1] = Math.min(point[1], union[1]);
            }
        }
        return shotCount;
    }
}
